package com.purengage.ipilih;

import java.util.ArrayList;

import com.purengage.ipilih.lib.EntryItem;
import com.purengage.ipilih.lib.Item;
import com.purengage.ipilih.lib.SectionItem;
import com.purengage.ipilih.lib.EntryAdapterRelawan;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

public class Relawan extends Activity implements OnItemClickListener {
	ArrayList<Item> items = new ArrayList<Item>();
	ListView listview;
	@Override
	protected void onCreate(Bundle savedInstanceState){
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_relawan);
		
		

		listview = (ListView) findViewById(R.id.list_relawan);
		items.add(new SectionItem("Desa A"));
		items.add(new EntryItem(R.drawable.status_g, "Relawan A", null, null, null));
		items.add(new EntryItem(R.drawable.status_g, "Relawan B", null, null, null));
		items.add(new SectionItem("Desa B"));
		items.add(new EntryItem(R.drawable.status_g, "Relawan C", null, null, null));
		items.add(new EntryItem(R.drawable.status_g, "Relawan D", null, null, null));
		items.add(new EntryItem(R.drawable.status_g, "Relawan E", null, null, null));
		items.add(new EntryItem(R.drawable.status_g, "Relawan F", null, null, null));
		items.add(new EntryItem(R.drawable.status_g, "Relawan G", null, null, null));
		EntryAdapterRelawan adapter = new EntryAdapterRelawan(this, items);
		listview.setAdapter(adapter);
		listview.setOnItemClickListener(this);
		
		View.OnClickListener handler = new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				switch (v.getId()) {
				case R.id.addRelawan:
					Intent i = new Intent(getApplicationContext(), AddRelawan.class);					
					startActivity(i);
					break;

				default:
					break;
				}
				
			}
			
		};
		
		findViewById(R.id.addRelawan).setOnClickListener(handler);
		
	}

	

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
		// TODO Auto-generated method stub
		EntryItem item = (EntryItem)items.get(position);
		Toast.makeText(this, "You clicked " + item.title, Toast.LENGTH_SHORT).show();
		
		Intent i = new Intent(Relawan.this, DetailRelawan.class);
		switch (position) {
		case 1:
			startActivity(i);
			break;

		default:
			break;
		}
		
	}
	
	public static Intent createIntent(Context context) {
		Intent i = new Intent(context, Main.class);
		i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		return i;
	}

}
